package com.atguigu.lease.web.admin.custom.convert;



import com.atguigu.lease.model.enums.ItemType;
import com.baomidou.mybatisplus.annotation.IdType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @ClassName StringToItemTypeConverter
 * @Author heartFade
 * @Date 2025-04-24 18:41
 * @Version 1.0
 * @Description 实现WebDataBinder的自定义转化为枚举
 **/
//@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {

    @Override
    public ItemType convert(String source) {
        ItemType[] values = ItemType.values();
        if(values!=null&&values.length>0)
        {
            for(ItemType type:values)
            {
                if(String.valueOf(type.getCode()).equals(source))
                    return type;
            }
        }
        return null;
    }
}
